package com.sx.controller;

import com.sx.service.CategoryService;
import com.sx.service.serviceImpl.CategoryServiceImpl;
import jakarta.servlet.ServletException;
import jakarta.servlet.annotation.WebServlet;
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;

import java.io.IOException;
import java.io.Serial;

@WebServlet("/checkCategoryIdExists.action")
public class checkCategoryIdExists extends HttpServlet {
    @Serial
    private static final long serialVersionUID = 1L;
    private final CategoryService categoryService = new CategoryServiceImpl();

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.setCharacterEncoding("UTF-8");
        resp.setContentType("text/html;charset=UTF-8");
        String id = req.getParameter("id");
        if (categoryService.checkIdExists(id)) {
            resp.getWriter().write("true");
        } else {
            resp.getWriter().write("false");
        }
    }
}
